package seo.dale.util.database;

import org.apache.commons.lang3.StringUtils;

public class SequenceUtils {
	
	/**
	 * Increment a sequence with Prefix.
	 * @param str
	 * @param prefixSize
	 * @param sequenceSize
	 * @return
	 */
	public static String incrementPrefix(String str, int prefixSize, int sequenceSize) {
		if (str == null || str.length() != prefixSize + sequenceSize) {
			throw new IllegalArgumentException();
		}
		String prefix = str.substring(0, prefixSize);
		String sequence = str.substring(prefixSize);
		String nextSequence = incrementPadding(sequence, sequenceSize);
		return prefix + nextSequence;
	}

	/**
	 * Increment a sequence with Padding.
	 * @param str
	 * @param size
	 * @return
	 */
	public static String incrementPadding(String str, int size) {
		if (str == null || str.length() != size) {
			throw new IllegalArgumentException();
		}
		int num = Integer.parseInt(str) + 1;
		str = Integer.toString(num);
		str = StringUtils.leftPad(str, size, "0");
		return str;
	}

}
